home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / WSKSERVM.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  157 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.11  $
  6. //
  7. // Winsock for OWL subsystem.
  8. // Based on work by Paul Pedriana, 70541.3223@compuserve.com
  9. //----------------------------------------------------------------------------
  10. #if !defined(OWL_WSKSERVM_H)
  11. #define OWL_WSKSERVM_H
  12.  
  13. #if !defined(OWL_DEFS_H)
  14. # include <owl/defs.h>
  15. #endif
  16. #if !defined(OWL_WINDOW_H)
  17. # include <owl/window.h>
  18. #endif
  19. #if !defined (_WINSOCKAPI_)
  20. # include <winsock.h>
  21. #endif
  22.  
  23. #if defined(BI_NAMESPACE)
  24. namespace OWL {
  25. #endif
  26.  
  27. // Generic definitions/compiler options (eg. alignment) following the 
  28. // definition of classes
  29. #include <services/posclass.h>
  30.  
  31. #define WINSOCK_NOERROR (int)0
  32. #define WINSOCK_ERROR   (int)SOCKET_ERROR
  33.  
  34. //
  35. // Is supposedly in RFC 883.
  36. //
  37. #define N_MAX_SERVICE_NAME 128
  38. #define MSG_SERVICE_NOTIFY ((UINT)(WM_USER+302))
  39.  
  40. class _OWLCLASS TServiceManager;
  41.  
  42. //
  43. // class TServiceWindow
  44. // ~~~~~ ~~~~~~~~~~~~~~
  45. // A private class created by the TServiceManager to catch notifications.
  46. //
  47. class _OWLCLASS TServiceWindow : public TWindow {
  48.   public:
  49.     TServiceWindow(TServiceManager* newServiceManagerParent);
  50.  
  51.   protected: 
  52.     // Object to pass notifications
  53.     //
  54.     TServiceManager* ServiceManagerParent;
  55.  
  56.     TResult DoNotification(TParam1 param1, TParam2 param2);
  57.  
  58.   DECLARE_RESPONSE_TABLE(TServiceWindow);
  59. };
  60.  
  61. //
  62. // class TServiceEntry
  63. // ~~~~~ ~~~~~~~~~~~~~
  64. // Encapsulates information about a service.
  65. //
  66. class _OWLCLASS TServiceEntry : public servent {
  67.   public:
  68.     TServiceEntry();
  69. };
  70.  
  71. //
  72. // class TServiceManager
  73. // ~~~~~ ~~~~~~~~~~~~~~~
  74. // Encapsulates service database functions.
  75. //
  76. class _OWLCLASS TServiceManager {
  77.   public:
  78.     TServiceManager();
  79.     virtual ~TServiceManager();
  80.  
  81.     int   GetLastError();
  82.     int   GetLastServiceCompletion();
  83.     int   GetService(TServiceEntry*& sEntry, ushort port, const char* szProtocol = 0);
  84.     int   GetService(TServiceEntry*& sEntry, const char* szName,
  85.                      const char* szProtocol = 0);
  86.     int   GetServicePort(char* szName, ushort& port, const char* szProtocol = 0);
  87.     int   GetServiceName(ushort port, char* szName, const char* szProtocol = 0);
  88.     int   GetServiceAsync(HANDLE& hService, ushort port, const char* szProtocol = 0);
  89.     int   GetServiceAsync(HANDLE& hService, char* szName, const char* szProtocol = 0);
  90.     int   GetServiceAsync(TWindow& wndNotify, HANDLE& hService, ushort port,
  91.                           const char* szProtocol = 0, uint nMessage = MSG_SERVICE_NOTIFY,
  92.                           char* chBuffer = 0);
  93.     int   GetServiceAsync(TWindow& wndNotify, HANDLE& hService, char* szName,
  94.                           const char* szProtocol = 0, uint nMessage = MSG_SERVICE_NOTIFY,
  95.                           char* chBuffer = 0);
  96.     int   CancelServiceRequest(HANDLE hService = 0);
  97.     bool  GetServiceRequestCompleted();
  98.  
  99.   public_data:
  100.     //Set to point to chServiceBuffer.
  101.     //
  102.     TServiceEntry* ServiceEntry;
  103.  
  104.   protected:
  105.     int            LastError;                       // Last error code
  106.     int            OutstandingServiceRequests;      // Count of total requests done by myself that haven't completed yet.
  107.     bool           LastServiceRequestCompleted;     // Is the last request done?
  108.     char           ServiceBuffer[MAXGETHOSTSTRUCT]; // Used for calls to WSAAsync...()
  109.     HANDLE         LastServiceRequest;              // Handle of last service request
  110.     TServiceWindow Window;                          // Private window for catching notification
  111.  
  112.     void ServiceCompleted(int nError);
  113.  
  114.   friend class TServiceWindow;
  115. };
  116.  
  117. // Generic definitions/compiler options (eg. alignment) following the 
  118. // definition of classes
  119. #include <services/posclass.h>
  120.  
  121. #if defined(BI_NAMESPACE)
  122. } // namespace OWL
  123. #endif
  124.  
  125. //----------------------------------------------------------------------------
  126. // Inline implementations
  127. //
  128.  
  129. //
  130. // Return the last error code.
  131. //
  132. inline int
  133. TServiceManager::GetLastError()
  134. {
  135.   return LastError;
  136. }
  137.  
  138. //
  139. // Return the last service completion.
  140. //
  141. inline int
  142. TServiceManager::GetLastServiceCompletion()
  143. {
  144.   return LastServiceRequestCompleted;
  145. }
  146.  
  147. //
  148. // Return true if the last service requested has been completed.
  149. //
  150. inline bool
  151. TServiceManager::GetServiceRequestCompleted()
  152. {
  153.   return LastServiceRequestCompleted;
  154. }
  155.  
  156. #endif  // OWL_WSKSERVM_H
  157.